package cn.sciento.starter.social.sina.config;

import cn.sciento.starter.social.core.common.configurer.SocialConnectionFactoryBuilder;
import cn.sciento.starter.social.core.common.connect.SocialApiAdapter;
import cn.sciento.starter.social.core.common.connect.SocialConnectionFactory;
import cn.sciento.starter.social.core.common.connect.SocialServiceProvider;
import cn.sciento.starter.social.core.common.connect.SocialTemplate;
import cn.sciento.starter.social.core.common.constant.ProviderEnum;
import cn.sciento.starter.social.core.provider.Provider;
import cn.sciento.starter.social.sina.connection.SinaApiAdapter;
import cn.sciento.starter.social.sina.connection.SinaConnectionFactory;
import cn.sciento.starter.social.sina.connection.SinaServiceProvider;
import cn.sciento.starter.social.sina.connection.SinaTemplate;
import org.springframework.context.annotation.Configuration;

@Configuration
public class SinaSocialBuilder implements SocialConnectionFactoryBuilder {
  public String getProviderId() {
    return ProviderEnum.sina.name();
  }
  
  public SocialConnectionFactory buildConnectionFactory(Provider provider) {
    String URL_AUTHORIZE = "https://api.weibo.com/oauth2/authorize";
    String URL_GET_ACCESS_TOKEN = "https://api.weibo.com/oauth2/access_token";
    String URL_GET_OPEN_ID = "https://api.weibo.com/oauth2/get_token_info";
    String URL_GET_USER_INFO = "https://api.weibo.com/2/users/show.json";
    provider.setAuthorizeUrl("https://api.weibo.com/oauth2/authorize");
    provider.setAccessTokenUrl("https://api.weibo.com/oauth2/access_token");
    provider.setOpenIdUrl("https://api.weibo.com/oauth2/get_token_info");
    provider.setUserInfoUrl("https://api.weibo.com/2/users/show.json");
    SinaApiAdapter apiAdapter = new SinaApiAdapter();
    SinaTemplate template = new SinaTemplate(provider);
    SinaServiceProvider serviceProvider = new SinaServiceProvider(provider, (SocialTemplate)template);
    return (SocialConnectionFactory)new SinaConnectionFactory(provider, (SocialServiceProvider)serviceProvider, (SocialApiAdapter)apiAdapter);
  }
}
